namespace WP.Commons
{
	using System;
	using System.Reflection;
	using System.Runtime.Serialization;
	using System.Security.Principal;
	using System.Security.Permissions;
	using System.Collections.Specialized;
    using System.Data;

	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	[Serializable]
	public class BaseException:Exception
	{

		private string mstrCodeSignNo="";
		private string mstrModuleName="";
		private string mstrMethodName="";
		private string mstrAbsolutePath="";
		private string mstrAbsoluteURL="";
		private string mstrFileName="";
		private string mstrFileLineNumber="";
		private string mstrFileColumnNumber="";
		private string mstrDataTime="";
        private string mstrBaseMethodName = "";
        private string mstrBaseFileName = "";
        private string mstrBaseFileLineNumber = "";
        private DataTable mdtStackInfo = null;


		public BaseException():base()
		{
			InitializeInformation();
		}
		public BaseException(string message):base(message)
		{
			InitializeInformation();
		}
		public BaseException(string message,Exception inner):base(message,inner)
		{
			InitializeInformation();
		}

		public string CodeSignNo
		{
			get
			{
				return mstrCodeSignNo;
			}
		}
		public string ModuleName
		{
			get
			{
				return mstrModuleName;
			}
		}
		public string MethodName
		{
			get
			{
				return mstrMethodName;
			}
		}
		public string AbsolutePath
		{
			get
			{
				return mstrAbsolutePath;
			}
		}
		public string AbsoluteURL
		{
			get
			{
				return mstrAbsoluteURL;
			}
		}
		public string FileName
		{
			get
			{
				return mstrFileName;
			}
		}
		public string FileLineNumber
		{
			get
			{
				return mstrFileLineNumber;
			}
		}
		public string FileColumnNumber
		{
			get
			{
				return mstrFileColumnNumber;
			}
		}

        public DataTable StackInfo
        {
            get
            {
                return mdtStackInfo;
            }
        }

        public string BaseMethodName
        {
            get
            {
                return mstrBaseMethodName;
            }
        }

        public string BaseFileName
        {
            get
            {
                return mstrBaseFileName;
            }
        }
        public string BaseFileLineNumber
        {
            get
            {
                return mstrBaseFileLineNumber;
            }
        }

		public string DataTime
		{
			get
			{
				return mstrDataTime;
			}
		}

		protected BaseException(SerializationInfo info, StreamingContext context) : base(info, context)
		{
			mstrCodeSignNo = info.GetString("mstrCodeSignNo");
			mstrModuleName = info.GetString("mstrModuleName");
			mstrMethodName = info.GetString("mstrMethodName");
			mstrAbsolutePath = info.GetString("mstrAbsolutePath");
			mstrAbsoluteURL = info.GetString("mstrAbsoluteURL");
			mstrFileName = info.GetString("mstrFileName");
			mstrFileLineNumber = info.GetString("mstrFileLineNumber");
			mstrFileColumnNumber = info.GetString("mstrFileColumnNumber");
			mstrDataTime = info.GetString("mstrDataTime");
            mstrBaseMethodName = info.GetString("mstrBaseMothedName");
            mstrBaseFileName = info.GetString("mstrBaseFileName");
            mstrBaseFileLineNumber = info.GetString("mstrBaseFileLineNumber");
		}

		[SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
		public override void GetObjectData( SerializationInfo info, StreamingContext context ) 
		{
			info.AddValue("mstrCodeSignNo", mstrCodeSignNo, typeof(string));
			info.AddValue("mstrModuleName", DateTime.Now.ToShortDateString());
			info.AddValue("mstrMethodName", mstrModuleName, typeof(string));
			info.AddValue("mstrAbsolutePath", mstrAbsolutePath, typeof(string));
			info.AddValue("mstrAbsoluteURL", mstrAbsoluteURL, typeof(string));
			info.AddValue("mstrFileName", mstrFileName, typeof(string));
			info.AddValue("mstrFileLineNumber", mstrFileLineNumber, typeof(string));
			info.AddValue("mstrFileColumnNumber", mstrFileColumnNumber, typeof(string));
			info.AddValue("mstrDataTime", mstrDataTime, typeof(string));
            info.AddValue("mstrBaseMethodName", mstrBaseMethodName, typeof(string));
            info.AddValue("mstrBaseFileName", mstrBaseFileName, typeof(string));
            info.AddValue("mstrBaseFileLineNumber", mstrBaseFileLineNumber, typeof(string));
			base.GetObjectData(info,context);
		}

		
		private void InitializeInformation()
		{
			ExceptionFileInfo info=ExceptionManager.GetExceptionInfo(this);
			
			if(info!=null)
			{
				mstrFileName=info.FileName;
				mstrFileLineNumber=info.FileLineNumber;
				mstrFileColumnNumber=info.FileColumnNumber;
				mstrMethodName=info.Method;
                mdtStackInfo = info.StackInfo;
                //mstrBaseMethodName = info.BaseMethod;
                //mstrBaseFileName = info.BaseFileName;
                //mstrBaseFileLineNumber = info.BaseFileLineNumber;
			}

			mstrModuleName=SysVar.CurrentSystemModule.ToString();
			mstrCodeSignNo=SysVar.CodeSignNo.ToString();
//			mstrAbsoluteURL=SysVar.AbsoluteURLReferrer;
//			mstrAbsolutePath=SysVar.AbsolutePath;
			mstrDataTime=DateTime.Now.ToShortDateString();
		}

       
	}
}
